{% extends '@!SonataAdmin/CRUD/base_list.html.twig' %}

{% block list_filters %}
    {% if admin.datagrid.filters %}
        {% form_theme form get_admin_template('filter', admin.code) %}

        <div class="col-xs-12 col-md-12 sonata-filters-box"
             style="display: {{ admin.datagrid.hasDisplayableFilters ? 'block' : 'none' }}"
             id="filter-container-{{ admin.uniqid() }}">
            <div class="box box-primary">
                <div class="box-body">
                    <form class="sonata-filter-form form-horizontal {{ admin.isChild and 1 == admin.datagrid.filters|length ? 'hide' : '' }}"
                          action="{{ admin.generateUrl('list') }}" method="GET" role="form">
                        {{ form_errors(form) }}

                        <div class="row">
                            <div class="col-sm-10">
                                <div class="row">
                                    {% set withAdvancedFilter = false %}
                                    {% for filter in admin.datagrid.filters %}
                                        {% set filterDisplayed = filter.isActive() or filter.options['show_filter'] is same as (true) %}
                                        {% set filterCanBeDisplayed = filter.options['show_filter'] is not same as(false) %}

                                        <div class="form-group col-sm-4 {% block sonata_list_filter_group_class %}{% endblock %}"
                                             id="filter-{{ admin.uniqid }}-{{ filter.name }}"
                                             sonata-filter="{{ filterCanBeDisplayed ? 'true' : 'false' }}"
                                             style="display: {% if filterDisplayed %}block{% else %}none{% endif %}">
                                            {% if filter.label is not same as(false) %}
                                                <label for="{{ form[filter.formName].children['value'].vars.id }}"
                                                       class="col-sm-3 control-label" style="padding-right: 0px;">{{ filter.label|trans({}, filter.translationDomain ?: admin.translationDomain) }}</label>
                                            {% endif %}
                                            {% set attr = form[filter.formName].children['type'].vars.attr|default({}) %}

                                            <div class="col-sm-6 advanced-filter">
                                                {{ form_widget(form[filter.formName].children['type'], {'attr':  attr}) }}
                                            </div>

                                            <div class="col-sm-8">
                                                {{ form_widget(form[filter.formName].children['value']) }}
                                            </div>

                                            <div>
                                                <label class="control-label">
                                                    <a href="#" class="sonata-toggle-filter sonata-ba-action"
                                                       filter-target="filter-{{ admin.uniqid }}-{{ filter.name }}"
                                                       filter-container="filter-container-{{ admin.uniqid() }}">
                                                        <i class="fa fa-minus-circle" aria-hidden="true"></i>
                                                    </a>
                                                </label>
                                            </div>
                                        </div>
                                    {% endfor %}
                                </div>
                            </div>
                            <div class="col-sm-2 text-center">
                                <input type="hidden" name="filter[_page]" id="filter__page" value="1">

                                {% set foo = form['_page'].setRendered() %}
                                {{ form_rest(form) }}

                                <div class="form-group">
                                    <button type="submit" class="btn btn-primary">
                                        <i class="fa fa-filter"
                                           aria-hidden="true"></i> {{ 'btn_filter'|trans({}, 'SonataAdminBundle') }}
                                    </button>

                                    <a class="btn btn-default"
                                       href="{{ admin.generateUrl('list', {filters: 'reset'}) }}">
                                        {{ 'link_reset_filter'|trans({}, 'SonataAdminBundle') }}
                                    </a>
                                </div>
                            </div>
                        </div>

                        {% for paramKey, paramValue in admin.persistentParameters %}
                            <input type="hidden" name="{{ paramKey }}" value="{{ paramValue }}">
                        {% endfor %}
                    </form>
                </div>
            </div>
        </div>
    {% endif %}
{% endblock %}